/**
 * 附件上传mixin
 */
import { getUploadUrl, getHeader, remove } from '@/api/attachment/attachment'
import { ACCEPT_CONFIG } from '@/components/uploader/js/config'

export default {
  data() {
    return {
      fileList: []
    }
  },
  computed: {
    atmUploadUrl() {
      return getUploadUrl()
    },
    atmHeaders() {
      return getHeader()
    },
    accept() {
      return ACCEPT_CONFIG.getAll().join(',')
    },
    limitSize() {
      return ACCEPT_CONFIG.getLimitSize()
    }
  },
  methods: {
    handleFileSuccess(response, file, fileList) {
      this.fileList.push(response.data)
    },
    async removeFile(row) {
      const res = await remove(row.id)
      if (res.code === 0) {
        this.fileList = this.fileList.filter(value => value !== row)
      }
    }
  }
}
